<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Aiwangyou
 *
 * @author Samuel
 */
require_once 'BaseChannel.php';

class Aiwangyou implements BaseChannel {

    function __construct() {
        //echo "construct";
    }

    //put your code here
    function android($data) {
        $appKey = "dedda973ef3e8409e14b66c42a2c76a8";
        $UID = "10165";
        $res = $this->pay_result_notify_process($UID, $appKey,"1");
        echo $res;
    }

    function ios($data) {
        $appKey = "dedda973ef3e8409e14b66c42a2c76a8";
        $UID = "10165";
		$res = $this->pay_result_notify_process($UID, $appKey,"0");
        echo $res;
    }

    private function pay_result_notify_process($UID, $MyAppKey,$platform) {
        $data['UID'] = $uid_check = $_POST['UID'];
        $data['orderID'] = $orderID = $_POST['orderID'];
        $data['total_fee'] = $total_fee = $_POST['total_fee'];
        $data['trade_status'] = $trade_status = $_POST['trade_status'];
        $data['time'] = $time = $_POST['time'];
        $data['sign'] = $sign = $_POST['sign'];
        $status = $trade_status == 'TRADE_FINISHED' ? 1 : 2;
        $callBackResult = "success";
        $order = new ChargeOrder();
        $order->log("Aiwangyou", $_POST);
        $sign_check = base64_encode(md5(md5(base64_encode($orderID) . $total_fee . $trade_status . md5($uid_check . substr(md5($MyAppKey), 8, 16) . $time)) . $time));
        if ($sign_check == $sign) {
            $order->recordOrder($status, $total_fee, $orderID, "aiwangyou", $platform,$uid_check);
        } else {
            $callBackResult = 'Sign is not ok!';
            //记录错误订单
        }
        return $callBackResult;
    }

}

?>
